$(function(){
	$(".head .right2 .fon .name").click(function(){
		$(".head .right2 .fon .more").slideToggle();
	})

	//产品
	$(".goods .tit ul li").click(function(){
		var catgroupId=$(this).attr("attr");
		var index=$(this).index();
		queryProduct(catgroupId,1,10);
		$(this).attr("class","li_select");
		$(this).siblings().removeAttr("class");
	})

	//支付
	$(".zffs_det a").click(function(){
		$(this).find("span").addClass("sp_select").parent().siblings("a").find("span").removeClass("sp_select");
	})

	//我的课程
	$(".course .tit a").hover(function(){
		var index=$(this).index();
		$(this).addClass("a_select").siblings("a").removeClass("a_select");
		$(".course .list").eq(index).show().siblings(".course .list").hide();
	})

	//资源下载
	$(".download .left .tit a").hover(function(){
		var index=$(this).index();
		$(this).addClass("a_select").siblings("a").removeClass("a_select");
		$(".download .left .det").eq(index).show().siblings(".download .left .det").hide();
	})

	//登录弹窗
	$(".head .right1 .a1").click(function(){
		$(".login_pop").show();
	})
	$(".close").click(function(){
		$(".login_pop").hide();
	})
	
	function queryProduct(catgroupId,page,rows){
		var update_url = "product/list.html";
		$.ajax({	
			url: update_url,
			type: 'post',
			dataType: 'html',
			contentType : "application/json;charset=UTF-8",
			data:JSON.stringify({page:page,rows:rows,catgroup:{catgroupId:catgroupId}}),
			success: function(data) {
				$("#product-list").html(data);
			}
		});
	}
	
	/* 复制文本内容*/
    $(".dwfz").zclip({
        path: "/website/static/common/jquery-zclip-master/ZeroClipboard.swf",
        copy: function(){
        return $("#token_url").val();
        },
        afterCopy:function(){/* 复制成功后的操作 */
            var $copysuc = $("<div class='copy-tips'><div class='copy-tips-wrap'>☺ 复制成功</div></div>");
            $("body").find(".copy-tips").remove().end().append($copysuc);
            $(".copy-tips").fadeOut(3000);
        }
    });
	
});

function login(){
	$(".login_pop").show();
}

function helpBargain(token){
	var URL = "/website/web/bargain/goToBargain.do";
	$.ajax({	
		url: URL,
		type: 'post',
		dataType: 'json',
		contentType : "application/json;charset=UTF-8",
		data:{token:token},
		success: function(data) {
			alert(data.msg);
		}
	});
}

//生成订单
function createOrder(){
	var update_url = "/website/web/order/createOrder.do";
	$.ajax({	
		url: update_url,
		type: 'post',
		dataType: 'json',
		contentType : "application/json;charset=UTF-8",
		data: JSON.stringify({orderNo:'O2017050611002',storeId:1001,userId:2,status:"M",totalAmount:180.00,quantity:3,discount:25.5,invoiceTitle:"智子科技",mark:"请速度发货",addressId:1,
			orderItemList:[{productId:9,status:"M",price:90,totalAmount:160,quantity:2,discount:20},{productId:10,status:"M",price:25.5,totalAmount:20,quantity:1,discount:5.50}]}),
		success: function(data) {
			alert(data.order.orderId);
		}
	});
}

function createProduct(){
	var update_url = "/website/backstage/product/add.do";
	$.ajax({
		url: update_url,
		type: 'post',
		dataType: 'json',
		contentType : "application/json;charset=UTF-8",
		data:JSON.stringify({"partnum":'D0000006',"name":'PS 刷笔 2016官方原版34位',"productType":'PRODUCT_BEAN',"categoryId":2
		}),
		success: function(data) {
			alert(data.product.productId);
		}
	});
}